<?php
	class loaichuyenmucdb
	{
		public function Them($TenLoaiChuyenMuc = "", $MaChuyenMuc = 0)
		{
			$sql = "INSERT INTO loaichuyenmuc(TenLoaiChuyenMuc, MaChuyenMuc)
						   VALUES('$TenLoaiChuyenMuc', $MaChuyenMuc)";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaLoaiChuyenMuc = 0, $TenLoaiChuyenMuc = "", $MaChuyenMuc = 0)
		{
			$sql = "UPDATE loaichuyenmuc 
					SET TenLoaiChuyenMuc = '$TenLoaiChuyenMuc',
						MaChuyenMuc = $MaChuyenMuc 
					WHERE MaLoaiChuyenMuc = $MaLoaiChuyenMuc";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongBaiViet($MaLoaiChuyenMuc = 0)
		{
			$sql = "SELECT * FROM baiviet WHERE 1";
			if($MaLoaiChuyenMuc > 0)
				$sql.= " AND MaLoaiChuyenMuc = $MaLoaiChuyenMuc";
				
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($MaLoaiChuyenMuc = 0)
		{
			$sql = "DELETE FROM loaichuyenmuc 
					WHERE MaLoaiChuyenMuc = $MaLoaiChuyenMuc";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM loaichuyenmuc";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaLoaiChuyenMuc = 0, $TenLoaiChuyenMuc = "", $MaChuyenMuc = 0)
		{
			$sql = "SELECT * 
					FROM loaichuyenmuc 
					WHERE 1";
			
			if($MaLoaiChuyenMuc > 0)
				$sql .= " AND MaLoaiChuyenMuc = $MaLoaiChuyenMuc";
				
			if($TenLoaiChuyenMuc != "")
				$sql .= " AND TenLoaiChuyenMuc = '$TenLoaiChuyenMuc'";
				
			if($MaChuyenMuc > 0)
				$sql .= " AND MaChuyenMuc = $MaChuyenMuc";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>